<?php


function login_to_db()
{
	$dbhost = "localhost";
	$user = "admin";
	$pass = "password";	
	
	$connection = mysql_connect($dbhost,$user,$pass) or die ("couldn't connect");
	return $connection;
	
}
function create_db()
{
	
	$connection = login_to_db();
	$ok = mysql_query("create database gawdb;") or die("couldn't create gawdb");
	if($ok) echo "gawdb is created.";
}



function drop_db()
{
	//this will delete the whole database
	$connection = login_to_db();
	$ok = mysql_query("drop database gawdb;") or die("couldn't delete gawdb");
	if($ok) echo "gawdb is deleted.";
}


function get_ready()
{
	//login to db and select gawdb so that we are ready to execute queries
	$connection = login_to_db();
	$db = mysql_select_db("gawdb",$connection) or die ("couldn't select db");
	return $connection;
}

function create_gaw_table()
{
	$connection = get_ready();
	$sql = "CREATE TABLE gaw (
  id int(11) NOT NULL AUTO_INCREMENT,
  slangBurglish text,
  slangBurmese text,
  definitionBurglish text,
  definitionBurmese text,
  exampleBurglish text,
  exampleBurmese text,
  voteup int(11) default 0,
  votedown int(11) default 0,
  author text,
  offensiveness int(11) default 0,
  completed int(11) default 0,
  token int(11) default 0,
  date DATETIME,
   PRIMARY KEY(id),
  INDEX slangb(slangBurmese(100)),
  INDEX slang(slangBurglish(100)))
   ;";
	$ok = mysql_query($sql) or die ("something went wrong during table creation");
	
	mysql_close($connection);
	echo "<br>gaw table created";
	
	//token 1 is a lock, if it's 0 -> unlock; will be used for having the user help translate
	// completed is used to find slangs which are only available in one language... do we really need it??
	// offensiveness is a value to see how offensive a slang is
}

function create_sound_table()
{
	$connection = get_ready();
	$sql = "CREATE TABLE `sound` (
  `word` text,
  `homophone` text,
  `score` int(11) default 0)";
	$ok = mysql_query($sql) or die ("something went wrong during table creation");
	mysql_close($connection);
	
	echo "<br>sound table created";
}

function create_temp_storage_table()
{
	$connection = get_ready();
	$sql = "CREATE TABLE tempstorage (
  id int(11),
   slangBurmese text,
   definitionBurmese text,
  exampleBurmese text,
  authorBurmese text,
  good int(11) default 0,
  bad int(11) default 0
 )
   ;";
	
	
	$ok = mysql_query($sql) or die ("something went wrong during table creation");
	
	mysql_close($connection);
	echo "<br>tempstorage table created";
	
	//token 1 is a lock, if it's 0 -> unlock; will be used for having the user help translate
	// completed is used to find slangs which are only available in one language... do we really need it??
	// offensiveness is a value to see how offensive a slang is
}

function del_gaw_data()
{
	$connection = get_ready();
	$sql = "delete from gaw;";
	$ok = mysql_query($sql) or die ("cannot delete data from gaw table");
	mysql_close($connection);
	
	echo "<br>gaw data deleted";
}

function del_sound_data()
{
	$connection = get_ready();
	$sql = "delete from sound;";
	$ok = mysql_query($sql) or die ("cannot delete data from sound table");
	mysql_close($connection);
	
	echo "<br>sound data deleted";
}

// new table structure added to 30
function add_authorBurmese_to_gaw()
{
	$connection = get_ready();
	$sql = "alter table gaw add column authorBurmese text after author;";
	$ok = mysql_query($sql) or die ("cannot delete data from sound table");
	mysql_close($connection);
	echo "<br>column 'authorBurmese' has been added to gaw table</br>";
}

function migrate30()
{
	$num = get_number_of_rows("gaw");
	echo "There are $num rows<br>";
	for($i=1; $i<=$num; $i++)
	{
		$result = select_by_id($i);
		$row = mysql_fetch_array($result);
		if($row['slangBurmese']!= NULL)
		{
			//echo "$i: burmese not null";
			$author= $row['author'];
			//echo "--adding: $author<br>";
			add_author($i, $author);
			echo "*";
			
		}
		else
		{
			//echo "$i: burmese is null<br>";
			echo "*";
		}
	}
	
}

function add_author($id, $v)
{
	$connection = get_ready();
	$sql = "UPDATE gaw SET authorBurmese='$v' where id=$id";
	mysql_query($sql);
	
	//set the author column back to NULL
	$sql = "UPDATE gaw SET author='NULL' where id=$id";
	mysql_query($sql);
	
	mysql_close($connection);

}

//end functions for 30 data migration


function update_slangBurmese($id, $v)
{
	$connection = get_ready();
	$sql = "UPDATE gaw SET slangBurmese='$v' where id=$id";
	mysql_query($sql);
	
	mysql_close($connection);

}

function update_slangBurglish($id, $v)
{
	$connection = get_ready();
	$sql = "UPDATE gaw SET slangBurglish='$v' where id=$id";
	mysql_query($sql);
	
	mysql_close($connection);

}

function encode_special_chars()
{
	$num = get_number_of_rows("gaw");
	echo "There are $num rows<br>";
	for($i=1; $i<=$num; $i++)
	{
		$result = select_by_id($i);
		$row = mysql_fetch_array($result);
		if($row['slangBurmese']!= NULL)
		{
			//echo "$i: burmese not null";
			$word= $row['slangBurmese'];
			//echo "--adding: $author<br>";
			$word = burmese_special_char_encoder($word);
			update_slangBurmese($i, $word);
			echo "*";
			
		}
		else
		{
			//echo "$i: burmese is null<br>";
			echo "=";
		}
	}
	
	
	//do it again for slangBurglish
	for($i=1; $i<=$num; $i++)
	{
		$result = select_by_id($i);
		$row = mysql_fetch_array($result);
		if($row['slangBurglish']!= NULL)
		{
			//echo "$i: burmese not null";
			$word= $row['slangBurglish'];
			//echo "--adding: $author<br>";
			$word = burmese_special_char_encoder($word);
			update_slangBurglish($i, $word);
			echo "*";
			
		}
		else
		{
			//echo "$i: burmese is null<br>";
			echo "=";
		}
	}
	
}

function show_gaw()
{
	//not worknig yet
	$connection = get_ready();
	$sql = "select slangBurmese, slangBurglish from gaw;";
	$ok = mysql_query($sql) or die ("can't exe query");
	mysql_close($connection);
 
}
function show_sound()
{
	//working yet
	$connection = get_ready();
	$sql = "select * from sound;";
	$ok = mysql_query($sql) or die ("can't exe query");
	mysql_close($connection);
 
}

function insert_into_gaw_burglish($slang, $def, $example, $author)
{
	$date = date("Y-m-d H:i:s");
	$connection = get_ready();
	
	$slang = burmese_special_char_encoder($slang);
	
	$slang = str_replace("'","''",$slang); // da dway problem
	$slang = str_replace("\\","\\\\",$slang); // ei problem
	
	$def = str_replace("'","''",$def); // da dway problem
	$def = str_replace("\\","\\\\",$def); // ei problem
	
	$example = str_replace("'","''",$example); // da dway problem
	$example = str_replace("\\","\\\\",$example); // ei problem
	
	$author = str_replace("'","''",$author); // da dway problem
	$author = str_replace("\\","\\\\",$author); // ei problem
	
	
	
	
	$sql = "insert into gaw (slangBurglish, definitionBurglish,exampleBurglish,author,date)
            values ('$slang', '$def', '$example','$author','$date');";

	//echo $sql;
	mysql_query($sql,$connection) or die ("couldn't exe query");
	mysql_close($connection);
}

function insert_into_gaw_burmese($slang, $def, $example, $author,$inenglish)
{
	$date = date("Y-m-d H:i:s");
	$connection = get_ready();
	
	$slang = burmese_special_char_encoder($slang);
	
	$slang = str_replace("'","''",$slang); // da dway problem
	$slang = str_replace("\\","\\\\",$slang); // ei problem
	
	$def = str_replace("'","''",$def); // da dway problem
	$def = str_replace("\\","\\\\",$def); // ei problem
	
	$example = str_replace("'","''",$example); // da dway problem
	$example = str_replace("\\","\\\\",$example); // ei problem
	
	$author = str_replace("'","''",$author); // da dway problem
	$author = str_replace("\\","\\\\",$author); // ei problem
	
	$inenglish = str_replace("'","''",$inenglish); // da dway problem
	$inenglish = str_replace("\\","\\\\",$inenglish); // ei problem
	
	
	
	//echo "about to enter: $slang";
	$sql = "insert into gaw (slangBurmese, definitionBurmese,exampleBurmese,authorBurmese,date,slangBurglish)
            values ('$slang', '$def', '$example','$author','$date','$inenglish');";

	//echo "<br>$sql<br>";
	mysql_query($sql,$connection) or die ("couldn't exe query: $sql");
	mysql_close($connection);
}

function select_from_burglish($word)
{
	
	$connection = get_ready();
	
	$word = burmese_special_char_encoder($word);
	
	
	$word = trim($word);
	$word = str_replace("'","''",$word);
	$word = str_replace("\\","\\\\",$word);
	//$result = mysql_query("SELECT slangBurglish, definitionBurglish,exampleBurglish,author,voteup,votedown,id FROM gaw where slangBurglish='$word' ORDER BY voteup DESC;");
	
	$query_string = "SELECT * FROM gaw where slangBurglish='$word'";
	
	/*$sub_result = mysql_query("SELECT DISTINCT slangBurmese from gaw where slangBurglish = '$word';");
	$bslang = "";
	while($sub_row = mysql_fetch_array($sub_result))
	{
		if($sub_row['slangBurmese']!= NULL)
		{
			//echo "need to append";
			$bslang = $sub_row['slangBurmese'];
			$bslang = trim($bslang);
			$bslang = str_replace("'","''",$bslang);
			$query_string = $query_string . " OR slangBurmese = '$bslang' AND slangBurglish IS NULL";
		}
	}
	
	$query_string = $query_string . " OR slangBurmese = '$bslang' AND slangBurglish != '$word'";*/
	$query_string = $query_string . "  ORDER BY voteup DESC;";
	$result = mysql_query($query_string);
	//$result = mysql_query("SELECT * FROM gaw where slangBurglish='$word' OR ( slangBurmese = (select slangBurmese from gaw where slangBurglish = '$word') AND slangBurglish IS NULL) ORDER BY voteup DESC;");
	
	mysql_close($connection);
	return $result;
	
	//mysql> select slangBurmese, slangBurglish, voteup from gaw where slangBurglish =
 	//'myanmar' OR slangBurmese = 'jrefrm' AND slangBurglish IS NULL ORDER BY voteup
	//DESC;
	
}


function select_from_burmese($word)
{
	/*$connection = get_ready();
	//if $word contains aphostophe "'", the query is doomed
	//let's find aphostophe "'" and replace with double aphostophe "''"
	$word = trim($word);
	$word = str_replace("'","''",$word);
	
	$result = mysql_query("SELECT slangBurmese, definitionBurmese,exampleBurmese,author,voteup,votedown,id FROM gaw where slangBurmese='$word'ORDER BY voteup DESC;");
	
	
	mysql_close($connection);
	return $result;
	*/
	
	
	//REQUIRED: decoded burmese special char 
	
	$connection = get_ready();
	//if $word contains aphostophe "'", the query is doomed
	//let's find aphostophe "'" and replace with double aphostophe "''"
	
	$word = burmese_special_char_encoder($word);
	$word = trim($word);
	$word = str_replace("'","''",$word);
	$word = str_replace("\\","\\\\",$word);
	
	$query_string = "SELECT * FROM gaw where slangBurmese='$word'";
	
	/*$sub_result = mysql_query("SELECT DISTINCT slangBurglish from gaw where slangBurmese = '$word';");
	$bslang = "";
	while($sub_row = mysql_fetch_array($sub_result))
	{
		if($sub_row['slangBurglish']!= NULL)
		{
			//echo "need to append";
			$bslang = $sub_row['slangBurglish'];
			$bslang = trim($bslang);
			$bslang = str_replace("'","''",$bslang);
			//echo "searching for $bslang";
			$query_string = $query_string . " OR slangBurglish = '$bslang' AND slangBurmese IS NULL";
		}
	}
	
	
	$query_string = $query_string . " OR slangBurglish = '$bslang' AND slangBurmese != '$word'";*/
	$query_string = $query_string . "  ORDER BY voteup DESC;";
	$result = mysql_query($query_string);
	
	
	mysql_close($connection);
	return $result;
	
}


function select_burmese_with_no_bglish($bglish_word)
{
	//this will return burmese slang which has no burglish def
	$connection = get_ready();
	//if $word contains aphostophe "'", the query is doomed
	//let's find aphostophe "'" and replace with double aphostophe "''"
	$word = trim($word);
	$word = str_replace("'","''",$word);
	
	$result = mysql_query("SELECT slangBurmese, definitionBurmese,exampleBurmese,authorBurmese,voteup,votedown,id FROM gaw where slangBurmese='$word'ORDER BY voteup DESC;");
	
	
	mysql_close($connection);
	return $result;
	
}

function isPresent_gaw($slang,$key_pref)
{
	//REQUIRED: decoded burmese special char 
	
		$slang = burmese_special_char_encoder($slang);
	
	
	$slang = trim($slang);
	$slang = str_replace("'","''",$slang);
	$slang = str_replace("\\","\\\\",$slang);
	

	$connection = get_ready();
	if($key_pref=="bglish")
	{
		$result = mysql_query("SELECT slangBurglish FROM gaw where slangBurglish = '$slang'; ");
	}
	else if($key_pref=="bur")
	{
		//echo " -right before the query: slang = $slang";
		//echo "SELECT slangBurmese FROM gaw where slangBurmese = '$slang'; ";
		$result = mysql_query("SELECT slangBurmese FROM gaw where slangBurmese = '$slang'; ");
	}
	
	$num = mysql_num_rows($result);
	mysql_close($connection);
	if($num ==0)
	{
		//echo " --is present returns false";
		return false;
	}
	else
	{
		//echo " --is present returns true";
		return true;
	}
	
}


function increase_voteup($id)
{
	//
	$connection = get_ready();
	$result = mysql_query("SELECT voteup FROM gaw where id=$id;");
	$row = mysql_fetch_array($result);
	
	$vote = $row['voteup'] + 1;
	$sql = "UPDATE gaw SET voteup=$vote WHERE id=$id";
	mysql_query($sql);
	mysql_close($connection);
	
}

function increase_votedown($id)
{
	$connection = get_ready();
	$result = mysql_query("SELECT votedown FROM gaw where id=$id;");
	$row = mysql_fetch_array($result);
	
	$vote = $row['votedown'] + 1;
	$sql = "UPDATE gaw SET votedown=$vote WHERE id=$id";
	mysql_query($sql);
	mysql_close($connection);
}

function get_number_of_rows($table)
{
	$connection = get_ready();
	$result = mysql_query("SELECT count(*) from $table;");
	$row = mysql_fetch_array($result);
	
	mysql_close($connection);
	return $row['count(*)'];
}
function get_random_ids()
{
	$count = 4; // this will give you n random ids
	
	//get the number of rows in gaw table
	$rows = get_number_of_rows("gaw");
	$result[0] = "NULL";
	if($rows < $count)
	{
		echo "not enough entries to display random slangs";
	}
	else
	{
		$number = rand(1,$rows);
		$result[0] = $number;
		
		for($i =1; $i < $count; $i++)
		{
		//echo $i;
		$done = false;
			while($done==false)
			{
				//echo "im in while loop";
				$number = rand(1,$rows);
				if(in_array($number,$result))
				{
					//echo "$number is in array";
					$done = false;
				}
				else
				{
					//array_push($result, $number);
					$result[$i] = $number;
					//echo "the result";
					//echo $result[$i];
					$done = true;
				}
			}
		}
	}
	
	return $result;
	
}
function select_by_id($id)
{
	$connection = get_ready();
	$result = mysql_query("SELECT * FROM gaw where id=$id;");
	
	
	mysql_close($connection);
	return $result;
}

function select_this_many($limit)
{
	$connection = get_ready();
	$result = $result = mysql_query("SELECT DISTINCT * FROM gaw ORDER BY id limit $limit;");
	mysql_close($connection);
	return $result;
}

//--------------------pattern matching-------------------

function select_begins_with($begin,$key_pref)
{
	$connection = get_ready();
	$begin = trim($begin);
	$result = NULL;
	if($key_pref=="bur")
	{
		//echo "i'm lokkin for $begin <br>";
		$begin = str_replace("'","''",$begin);
		$result = mysql_query("SELECT DISTINCT slangBurmese FROM gaw where slangBurmese LIKE '$begin%';");
	}
	else
	{
		//echo "i'm in burglish";
		$result = mysql_query("SELECT DISTINCT slangBurglish FROM gaw where slangBurglish LIKE '$begin%';");
	}
	
	mysql_close($connection);
	return $result;

}

function select_ends_with($end,$key_pref)
{
	$connection = get_ready();
	$end = trim($end);
	$result = NULL;
	if($key_pref=="bur")
	{
		$end = str_replace("'","''",$end);
		$result = mysql_query("SELECT DISTINCT slangBurmese FROM gaw where slangBurmese LIKE '%$end';");
	}
	else
	{
		$result = mysql_query("SELECT DISTINCT slangBurglish FROM gaw where slangBurglish LIKE '%$end';");
	}
	
	mysql_close($connection);
	return $result;

}



function select_contains($contain,$key_pref)
{
	$connection = get_ready();
	$contain = trim($contain);
	$result = NULL;
	if($key_pref=="bur")
	{
		$contain = str_replace("'","''",$contain);
		$result = mysql_query("SELECT DISTINCT slangBurmese FROM gaw where slangBurmese LIKE '%$contain%';");
	}
	else
	{
		$result = mysql_query("SELECT DISTINCT slangBurglish FROM gaw where slangBurglish LIKE '%$contain%';");
	}
	
	mysql_close($connection);
	return $result;

}


function select_newest($limit)
{
	$connection = get_ready();
	//$word = trim($word);
	//$word = str_replace("'","''",$word);
	$result = mysql_query("SELECT * FROM gaw ORDER BY date DESC limit $limit;");
	
	
	mysql_close($connection);
	return $result;
}

function select_top($number)
{
	//select top vote up getters
	// the number of results is defined by $number
	$connection = get_ready();
	$result = mysql_query("SELECT * FROM gaw ORDER BY voteup DESC limit $number;");
	mysql_close($connection);
	return $result;
	
}
//=========================================================================
//     HTML functions
//==========================================================================

function print_main_menu()
{
	echo "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 align=\"left\">
<tr>
<td>&nbsp;&nbsp;<a class=\"menu\" href=\"index.php\">HOME</a>&nbsp;&nbsp;&nbsp;</td>
<td><a class=\"menu\" href=\"browse.php?start=1\">BROWSE</a>&nbsp;&nbsp;&nbsp;</td>
<td><a class=\"menu\" href=\"add.php?key_pref=bglish&edit=0\">DEFINE</a>&nbsp;&nbsp;&nbsp;</td>
<td><a class=\"menu\" href=\"newest.php\">NEWEST</a>&nbsp;&nbsp;&nbsp;</td>

<td><a class=\"menu\" href=\"about.php\">ABOUT THE SITE</a>&nbsp;&nbsp;&nbsp;</td>
</tr></table>";
	
	//<td><a class=\"menu\" href=\"index.php\">CONTACTS</a>&nbsp;&nbsp;&nbsp;</td>
	
}

function print_burmese_layout()
{
	
	echo "<!-- keyboard layout start -->





				<table border=0 cellpadding=0 cellspacing=0 width=\"170\" align=center >

				<tr>
				  <td valign=top align=left>
					<table border=0 cellpadding=0 cellspacing=0 width=\"45\">
                     <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('a')\">a</a></td><td>a</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('j')\">j</a></td><td>j</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('N')\">N</a></td><td>N</td></tr>
					<tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('B')\">B</a></td><td>B</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('M')\">M</a></td><td>M</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('<')\"><</a></td><td><</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('>')\">></a></td><td>></td></tr>
					 <tr><td class=keyboardlayout>&nbsp</td><td>&nbsp</td></tr>
					 
					 
					 
					 <tr ><td class=keyboardlayout ><a class=bur href=\"#\"  onclick=\"insert_at_cursor('u')\">u</a></td><td>u</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('c')\">c</a></td><td>c</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('*')\">*</a></td><td>*</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('C')\">C</a></td><td>C</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('i')\">i</a></td><td>i</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('p')\">p</a></td><td>p</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('q')\">q</a></td><td>q</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('Z')\">Z</a></td><td>Z</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('ps')\">ps</a></td><td>ps</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('n')\">n</a></td><td>n</td></tr>
					<tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('P')\">P</a></td><td>P</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('w')\">w</a></td><td>w</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('x')\">x</a></td><td>x</td></tr>
					 
					 
					</table>
				  </td>
				  <td valign=top align=center>
					<table border=0 cellpadding=0 cellspacing=0 width=\"45\" >
                     <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('\'')\">'</a></td><td>'</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('0000')\">\"</a></td><td>\"</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('e')\">e</a></td><td>e</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('y')\">y</a></td><td>y</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('z')\">z</a></td><td>z</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('A')\">A</a></td><td>A</td></tr>
					<tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('b')\">b</a></td><td>b</td></tr>
                    <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('r')\">r</a></td><td>r</td></tr>
                     <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor(',')\">,</a></td><td>,</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('&')\">&</a></td><td>&</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('v')\">v</a></td><td>v</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('0')\">0</a></td><td>0</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('o')\">o</a></td><td>o</td></tr>
                     <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('[')\">[</a></td><td>[</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('V')\">V</a></td><td>V</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('t')\">t</a></td><td>t</td></tr>
					 
					 <tr><td class=keyboardlayout>&nbsp</td><td>&nbsp</td></tr>
					  <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('{')\">{</a></td><td>{</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('0001')\">\</a></td><td>\</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('?')\">?</a></td><td>?</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('/')\">/</a></td><td>/</td></tr>
                     
					 
					</table>
				  </td>
				  <td valign=top align=right>
					<table border=0 cellpadding=0 cellspacing=0 width=\"45\">
					<tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('d')\">-d</a></td><td>d</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('D')\">-D</a></td><td>D</td></tr>
					<tr><td class=keyboardlayout>&nbsp</td><td>&nbsp</td></tr>
                     <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('S')\">-S</a></td><td>S</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('G')\">-G</a></td><td>G</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('T')\">-T</a></td><td>T</td></tr>
                     <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('I')\">-I</a></td><td>I</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('k')\">-k</a></td><td>k</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('K')\">-K</a></td><td>K</td></tr>
					<tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('Q')\">-Q</a></td><td>Q</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('W')\">-W</a></td><td>W</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('R')\">-R</a></td><td>R</td></tr>
                     <tr><td class=keyboardlayout>&nbsp</td><td>&nbsp</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('m')\">m</a></td><td>m</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('g')\">g</a></td><td>g</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('f')\">-f</a></td><td>f</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor(':')\">:</a></td><td>:</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor('s')\">-s</a></td><td>s</td></tr>
					 <tr><td class=keyboardlayout><a class=bur href=\"#\"  onclick=\"insert_at_cursor(';')\">;</a></td><td>;</td></tr>
                     
					
					
					</table>
				  </td>
				</tr>
				</table>









				<!--  keyboard layout end -->";
	
	
}


function print_right_column_bottom()
{
	//this create the right bottom column , the light yellow table
	echo "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 width=\"208\">

			<TR>
				<TD colspan=\"3\"><img src=\"images/light_top.gif\" border=0
					width=\"208\" height=\"27\"></TD>
			</TR>

			<TR>
				<TD background=\"images/light_left.gif\" width=\"17\"><img
					src=\"images/space.gif\" border=0 width=\"17\" height=\"1\"></TD>

				<TD bgcolor=\"CCCC99\"><img src=\"images/space.gif\" border=0
					width=\"176\" height=\"1\"><BR>
				<P class=\"textdark\">
				
				

				





				</TD>

				<TD background=\"images/light_right.gif\" width=\"17\"><img
					src=\"images/space.gif\" border=0 width=\"17\" height=\"1\"></TD>

			</TR>


			<TR>
				<TD colspan=\"3\"><img src=\"images/light_bott.gif\" border=0
					width=\"208\" height=\"22\"></TD>
			</TR>


		</TABLE>";
}


function burglish_content_right_top()
{
	//this content is shown on add page top right column, (aka) red column , when the input language is burglish
	
	echo "<p>Select Burmese radio button to type in burmese<br>

				

				<P>Burglish = the sound of burmese words spelled in english<br>
				<BR>";
				
	
}


function print_result_holder_top()
{
	//print the result holder top, the yellowish box top part
	echo "
		<TABLE BORDER=\"0\" CELLPADDING=0 CELLSPACING=0 width=\"464\" >

		<TR><TD colspan=\"3\"><img src=\"images/page_top.gif\" border=0 width=\"464\" height=\"27\"></TD></TR>

		<TR><TD background=\"images/page_left.gif\" width=\"23\"><img src=\"images/space.gif\" border=0 width=\"17\" height=\"1\"></TD>

		<TD bgcolor=\"CCCC99\" style=\"word-wrap:break-word;\" width=420><img src=\"images/space.gif\" border=\"0\" width=\"428\" height=\"1\"><BR>
		";
}

function print_result_holder_bottom()
{
	//print the result holder top, the yellowish box bottom part
	echo "
			</TD>

			<TD background=\"images/page_right.gif\" width=\"19\"><img src=\"images/space.gif\" border=0 width=\"16\" height=\"1\"></TD>

				</TR>
 


			<TR>
			<TD colspan=\"3\"><img src=\"images/page_bott.gif\" border=0 width=\"464\" height=\"22\"></TD></TR>


			</TABLE>
         ";
	
}

function print_result_old($word,$def,$example,$voteup,$votedown,$author,$id,$key_pref)
{
	if($key_pref=="bglish")
	{
		$styleclass = "textdark";
		//$link_class = "\\\"\\\"";
		$link_class = "light";
		$vote_class = "vote";
		
		$label_word = "word";
		$label_definition = "definition";
		$label_example = "example";
		$label_voteup = "cool";
		$label_votedown = "sucks";
		$label_defineItYourway = "Dont' like it? Define it your way";
		$label_tooltip_voteup = "vote up";
		$label_tooltip_votedown = "vote down";
		
		$decoded_word = burmese_special_char_decoder($word);
		
		
		$completed = get_completed($id);
		//html code to display translate image
		$show_image = "";
		
		if($completed==0)
		{
			$show_image = "<div id=changeme$id><td width='30%' align=right><img src=\"images/translate.gif\" id=image$id onmouseover=\"return overlay(this, 'hidden_form$id');\"></td></div>";
		}
		else if($completed==1)
		{
			$show_image = "<div id=changeme$id><td width='30%' align=right><img src=\"images/translated.gif\" id=image$id onmouseover=\"return overlay(this, 'hidden_form$id');\"></td></div>";
		}
	}
	else if($key_pref=="bur")
	{
		$styleclass = "textdarkb";
		$link_class = "lightb";
		$vote_class = "voteb";
		
		$label_word = "pum;vHk;";
		$label_definition = "t\"dyg,f";
		$label_example = "Oyrm";
		$label_voteup = "rdkuf";
		$label_votedown = "&GJ";
		$label_defineItYourway = "odyfrBuKdufzl;vm;? pdwfBuKdufxyf zGifhqkdcJhav";
		$label_tooltip_voteup = "vote up";
		$label_tooltip_votedown = "vote down";
		
		$decoded_word = burmese_special_char_decoder($word);
		//echo "print_result(): $word";
		
		$show_image = "";//no need to show 
	}
	
	echo "<TABLE BORDER=\"0\" CELLPADDING=0 CELLSPACING=0 width=\"400\" >
           <TR ><TD class=$styleclass width='20%'>$label_word</TD><TD class=$styleclass>$decoded_word</TD>$show_image</TR>
           <TR ><TD class=$styleclass>$label_definition</TD><TD colspan=2  class=$styleclass>$def</TD></TR>
           <TR ><TD class=$styleclass>$label_example</TD><TD colspan=2  class=$styleclass>$example</TD></TR>
           <TR ><TD colspan=3 class=$styleclass align=right>- $author</TD></TR>
           <TR><TD bgcolor=\"CCCC99\" colspan=3><img src=\"images/divider.gif\" border=\"0\" width=\"400\" height=\"10\"></TD></TR>
           <TR ><td colspan=3>
                <table width=\"395\">
                <tr>
                <TD colspan=3 class=$styleclass align=center>$voteup <a class =\"$vote_class\" href =\"search.php?slang=$word&key_pref=$key_pref&vote_flow=1&id=$id\" > $label_voteup <img src=\"images/uparrow.gif\" border=\"0\" width=\"15\" height=\"15\" alt=\"$label_tooltip_voteup\"></a></td>
                <TD colspan=3 class=$styleclass align=center>$votedown <a class =\"$vote_class\" href=\"search.php?slang=$word&key_pref=$key_pref&vote_flow=2&id=$id\"> $label_votedown <img src=\"images/downarrow.gif\" border=\"0\" width=\"15\" height=\"15\" alt=\"$label_tooltip_votedown\"></a></TD>
				
                </tr>
                </table>
                </td>
           </TR>
           <TR ><TD colspan=3 class=$styleclass align=center><a class =$vote_class href=\"add.php?key_pref=$key_pref&edit=2&word=$word\">$label_defineItYourway</a></TD></TR>
           </TABLE>
           
           ";
	//edit=2 will take user to redefine flow
	//vote_flow=1 is voting up
	//vote_flow=2 is voting down
	
}

function print_result($word,$def,$example,$voteup,$votedown,$author,$id,$key_pref)
{
	$completed = get_completed($id);
	
	if($key_pref=="bglish")
	{
		$styleclass = "textdark";
		
		$w_class = "result";
		$d_class = "textblack";
		$e_class = "textblack";
		
		
		//$link_class = "\\\"\\\"";
		$link_class = "light";
		$vote_class = "vote";
		
		$label_word = "word";
		$label_definition = "definition";
		$label_example = "example";
		$label_voteup = "cool";
		$label_votedown = "sucks";
		$label_defineItYourway = "Don\'t like it? Define it your way";
		$label_tooltip_voteup = "click here if you think this is cool";
		$label_tooltip_votedown = "click here if you think it sucks";
		
		$decoded_word = burmese_special_char_decoder($word);
		$decoded_def = burmese_special_char_decoder($def);
		$decoded_example = burmese_special_char_decoder($example);
		$decoded_author = burmese_special_char_decoder($author);
		
		$encoded_word = burmese_special_char_encoder($word);
		
		
		//html code to display translate image
		$show_image = "";
		
		if($completed==0)
		{
			$show_image = "<div id=changeme$id><td width='30%' align=right><img src=\"images/translate.gif\" id=image$id onmouseover=\"return overlay(this, 'hidden_form$id');\"></td></div>";
		}
		else if($completed==1)
		{
			$show_image = "<div id=changeme$id><td width='30%' align=right><img src=\"images/translated.gif\" id=image$id onmouseover=\"return overlay(this, 'hidden_form$id');\"></td></div>";
		}
		else if($completed==2)
		{
			$show_image = "<div id=changeme$id><td width='30%' align=right><img src=\"images/has_original.gif\" id=image$id onmouseover=\"return overlay(this, 'hidden_form$id');\"></td></div>";
		}
	}
	else if($key_pref=="bur")
	{
		$styleclass = "textdarkb";
		
		$w_class = "resultb";
		$d_class = "textblackb";
		$e_class = "textblackb";
		
		
		$link_class = "lightb";
		$vote_class = "voteb";
		
		$label_word = "pum;vHk;";
		$label_definition = "t\"dyg,f";
		$label_example = "Oyrm";
		$label_voteup = "rdkuf";
		$label_votedown = "&GJ";
		$label_defineItYourway = "odyfrBuKdufzl;vm;? pdwfBuKduf xyf zGifhqkdcJhav";
		$label_tooltip_voteup = "click here if you think this is cool";
		$label_tooltip_votedown = "click here if you think it sucks";
		
		$decoded_word = burmese_special_char_decoder($word);
		$decoded_def = burmese_special_char_decoder($def);
		$decoded_example = burmese_special_char_decoder($example);
		$decoded_author = burmese_special_char_decoder($author);
		//echo "print_result(): $word";
		
		$encoded_word = burmese_special_char_encoder($word);
		
		$show_image = "";//no need to show 
		
		if($completed==2)
		{
			$show_image = "<div id=changeme$id><td width='30%' align=right><img src=\"images/has_original.gif\" id=image$id onmouseover=\"return overlay(this, 'hidden_form$id');\"></td></div>";
		}
	}
	
	$n = get_number_of_rows("gaw");
	$back = $id - 1;
	$forward = $id + 1;
	if($id==1)
	{
		$previous = "";
	}
	else
	{
		$result = select_by_id($back);
		$row = mysql_fetch_array($result);
		if($row['slangBurmese']==NULL)
		{
			$s = $row['slangBurglish'];
			$k="bglish";
		}
		else
		{
			$s = $row['slangBurmese'];
			
			$k="bur";
		}
		//$previous = "<a class=light href=\"search.php?slang=$s&key_pref=$k&vote_flow=0\" onMouseover=\"ddrivetip('previous','43')\"; onMouseout=\"hideddrivetip()\"><<</a>";
		$previous = "<a class=light href=\"search.php?slang=$s&key_pref=$k&vote_flow=0\" onMouseover=\"ddrivetip('$s','43','','$k')\"; onMouseout=\"hideddrivetip()\"><<</a>";
	}
	if($id==$n)
	{
		$next = "";
	}
	else
	{
		$result = select_by_id($forward);
		$row = mysql_fetch_array($result);
		if($row['slangBurmese']==NULL)
		{
			$s = $row['slangBurglish'];
			//$s_decoded = burmese_special_char_decoder($s);
			$k="bglish";
		}
		else
		{
			$s = $row['slangBurmese'];
			//$s_decoded = burmese_special_char_decoder($s);
			//$s_decoded = htmlspecialchars($s_decoded,ENT_QUOTES);
			$k="bur";
		}
		$next = "<a class=light href=\"search.php?slang=$s&key_pref=$k&vote_flow=0\" onMouseover=\"ddrivetip('$s','32','','$k')\"; onMouseout=\"hideddrivetip()\">>></a>";
	}
	
	//$label_defineItYourway
	//$define_it ="";
	
	$shaker_code = "class=\"shakeimage\" onMouseover=\"init(this);rattleimage();ddrivetip2('$label_defineItYourway','170','','$key_pref')\" onMouseout=\"stoprattle(this);top.focus();hideddrivetip()\" onClick=\"top.focus()\"";
	//$define_it = "<a class =$vote_class href=\"add.php?key_pref=$key_pref&edit=2&word=$encoded_word\"><img src=\"images/comments_add.png\" border=0 onMouseover=\"ddrivetip2('$label_defineItYourway','170','','$key_pref');\" onMouseout=\"hideddrivetip();borderit(this,'white',0)\" $shaker_code></a>";
	
	//onMouseover=\"ddrivetip2('$label_defineItYourway','170','','$key_pref');\" onMouseout=\"hideddrivetip();\"
	
	$define_it = "<a class =$vote_class href=\"add.php?key_pref=$key_pref&edit=2&word=$encoded_word\"><img src=\"images/comments_add.png\" border=0  $shaker_code></a>";
	
	$voteup_shaker = "class=\"shakeimage\" onMouseover=\"init(this);rattleimage();ddrivetip2('$label_tooltip_voteup','100')\" onMouseout=\"stoprattle(this);top.focus();hideddrivetip()\" onClick=\"top.focus()\"";
	$votedown_shaker = "class=\"shakeimage\" onMouseover=\"init(this);rattleimage();onMouseover=ddrivetip2('$label_tooltip_votedown','100')\" onMouseout=\"stoprattle(this);top.focus();hideddrivetip()\" onClick=\"top.focus()\"";
	
	
	echo "<TABLE BORDER=\"0\" CELLPADDING=0 CELLSPACING=0 width=\"400\" >
           <TR ><TD  style=\"word-wrap:break-word;\"><div class=$w_class>$decoded_word</div><br><br></TD>$show_image</TR>
           <TR ><TD colspan=2  class=$d_class style=\"word-wrap:break-word;\" width=\"390\">$decoded_def<br><br></TD></TR>
           <TR ><TD colspan=2  class=$e_class style=\"word-wrap:break-word;\" width=\"390\">$decoded_example</TD></TR>
           <TR ><TD colspan=3 class=$styleclass align=right>- $decoded_author</TD></TR>
           <TR><TD bgcolor=\"CCCC99\" colspan=3><img src=\"images/divider.gif\" border=\"0\" width=\"400\" height=\"10\"></TD></TR>
           <TR ><td colspan=3 height=15 >
                <table border=0 width=\"395\">
                <tr>
				<td width=30>$previous</td>
                <TD width=120 colspan=3 class=$styleclass align=right valign=middle > <a class =\"$vote_class\" href =\"search.php?slang=$encoded_word&key_pref=$key_pref&vote_flow=1&id=$id\" >  <img src=\"images/uparrow.gif\" border=\"0\" width=\"15\" height=\"15\" $voteup_shaker></a></td>
				<td width=50 class=$styleclass valign=center>$voteup<a class =\"$vote_class\" href =\"search.php?slang=$encoded_word&key_pref=$key_pref&vote_flow=1&id=$id\" >   $label_voteup</a></td>
               

				<TD width=80 colspan=3 class=$styleclass align=right valign=center>$votedown <a class =\"$vote_class\" href=\"search.php?slang=$encoded_word&key_pref=$key_pref&vote_flow=2&id=$id\"> $label_votedown</a></TD>
				<td width=60 align=left valign=middle><a class =\"$vote_class\" href=\"search.php?slang=$encoded_word&key_pref=$key_pref&vote_flow=2&id=$id\"><img src=\"images/downarrow.gif\" border=\"0\" width=\"15\" height=\"15\"  $votedown_shaker></a></td>
				<td width=30 align=center>$define_it</td>
				<td width=30 align=right>$next</td>
                </tr>
                </table>
                </td>
           </TR>
          
           </TABLE>
           
           ";
	//edit=2 will take user to redefine flow
	//vote_flow=1 is voting up
	//vote_flow=2 is voting down
	
}

function print_search_box($key_pref="bglish")
{
	//ppl who search using this search box are not trying to vote, therefore, vote_flow is 0
	
	
	if($key_pref=="bur") 
	{ // print out the search box with burmese radio button checked
//	echo "<form name=\"search\" action=\"search.php\" method=\"get\" align = \"center\">
//		<input type=\"text\" name=\"slang\"  id=\"textbox\" class=textdark2b >
//        <input type=\"radio\" name=\"key_pref\" value=\"bur\" checked onClick=\"change('textbox','textdark2b');\">burmese
//        <input type=\"radio\" name=\"key_pref\" value=\"bglish\" onClick=\"change('textbox','header');\">burglish
//        <input type=\"hidden\" name=\"vote_flow\" value=0>
//        
//		<input type=\"submit\" value=\"&Smap\" class = \"buttonb\">
//			</form>
//         ";
	
	
	
	
	echo "
		<table border=0>
		<tr>
		<td>
		<form name=\"search\" action=\"search.php\" method=\"get\" align = \"center\">
		<input type=\"text\" name=\"slang\"  id=\"textbox\" class=textdark2b size=14>
		</td></tr>
 		<tr><td>
        <input type=\"radio\" name=\"key_pref\" value=\"bur\" checked onClick=\"change('textbox','textdark2b');\">burmese
        <input type=\"radio\" name=\"key_pref\" value=\"bglish\" onClick=\"change('textbox','header');\">burglish
        <input type=\"hidden\" name=\"vote_flow\" value=0>
        </td></tr>
		<tr><td align=center>
		<input type=\"submit\" value=\"&Smap\" class = \"buttonb\">
			</form>
		</td></tr>
		</table>
         ";
	}
	else
	{
		
//		echo "<form name=\"search\" action=\"search.php\" method=\"get\" align = \"center\">
//		<input type=\"text\" name=\"slang\" id=\"textbox\" class=header>
//        <input type=\"radio\" name=\"key_pref\" value=\"bur\" onClick=\"change('textbox','textdark2b');\">burmese
//        <input type=\"radio\" name=\"key_pref\" value=\"bglish\" checked onClick=\"change('textbox','header');\">burglish
//        <input type=\"hidden\" name=\"vote_flow\" value=0>
//		<input type=\"submit\" value=\"&Smap\" class = \"buttonb\">
//			</form>
//         ";

		echo "
		<table border=0>
		<tr>
		<td>
		<form name=\"search\" action=\"search.php\" method=\"get\" align = \"center\">
		<input type=\"text\" name=\"slang\" id=\"textbox\" class=header >
		</td></tr>
 		<tr><td>
        <input type=\"radio\" name=\"key_pref\" value=\"bur\" onClick=\"change('textbox','textdark2b');\">burmese
        <input type=\"radio\" name=\"key_pref\" value=\"bglish\" checked onClick=\"change('textbox','header');\">burglish
        <input type=\"hidden\" name=\"vote_flow\" value=0>
		</td></tr>
		<tr><td align = center>
		<input type=\"submit\" value=\"&Smap\" class = \"buttonb\">
			</form>
		</td></tr>
		</table>
         ";
		
	}
	
	
	

	
	
	
}

function print_random_slangs($idarray)
{
	//echo "i'm in print random";
	$size = count($idarray);
	//echo "size is: $size";
	for($i=0; $i < $size; $i++)
	{
		//echo "getting id: $idarray[$i]";
		$result = select_by_id($idarray[$i]);
		$row = mysql_fetch_array($result);
		
		if($row['slangBurmese']==NULL)
		{
			//print in english
			//echo "slangburmese is null; i'm gonna print in english";
			$word = $row['slangBurglish'];
			$decoded_word = burmese_special_char_decoder($word);
			$decoded_word = htmlspecialchars($decoded_word,ENT_QUOTES);
			echo "<a class=\"random\" href='search.php?slang=$word&key_pref=bglish&vote_flow=0' >";
			echo $decoded_word;
			echo "</a>";

			echo "<P class=\"textdark2\">";
			echo $row['definitionBurglish'] ;
			echo "<br></p>";
			echo "<P class=\"textlight\">";
			echo $row['exampleBurglish'] ;
			echo "<br></p>";
		}
		else
		{
			//print in burmese
			//echo "slangburmese is not null; i'm gonna print in burmese";
			$word = $row['slangBurmese'];
			$decoded_word = burmese_special_char_decoder($word);
			$decoded_word = htmlspecialchars($decoded_word,ENT_QUOTES);
			//$decoded_word = htmlspecialchars($word,ENT_QUOTES);
			echo "<a class=\"randomb\" href='search.php?slang=$word&key_pref=bur&vote_flow=0'>";
			echo $decoded_word;
			echo "</a>";

			echo "<P class=\"textdark2b\">";
			echo $row['definitionBurmese'] ;
			echo "<br></p>";
			echo "<P class=\"textlightb\">";
			echo $row['exampleBurmese'] ;
			echo "<br></p>";
		}
		
		//print_result($row['slangBurglish'],$row['definitionBurglish'],$row['exampleBurglish'],$row['voteup'],$row['votedown'],$row['author'],$row['id'],$key_pref);
	}
		
}



function cheap_guess($word, $key_pref, $array)
{
	if(strlen($word)==1)
	{
		//too short don't do anythin
		return $array;
	}
	$control = 15; //number of items to look by each method
	//$array = array();
	if($key_pref=="bur")
	{
		$styleclass = "randomb";
		$key_pref_value = "bur";
		
		$column = "slangBurmese";
		$message = "'gawGawmhawGhcJhw,f <br>";
		$message_singular = "'gawmhawGhcJhw,f <br>";
		$message_class = "textdarkb";
		
		$seperator = "  ";
		
		//we also need to process $word, how much we want to truncate, to be meaningful in burmese
	}
	else if($key_pref=="bglish")
	{
		$styleclass = "random";
		$key_pref_value = "bglish";
		
		$column = "slangBurglish";
		$message = "Maybe these are the words you were searching for...<br>";
		$message_singular = "Is this the one you were searching??<br>";
		$message_class = "textdark";
		$seperator = "  ";
	}
	
	
	$result1 = select_begins_with($word,$key_pref);
	$result2 = select_ends_with($word,$key_pref);
	$result3 = select_contains($word,$key_pref);
	
	$count = 1;
	$array_pointer= count($array);
	
	//printing out result from select begin with
	//echo "begin with";
	while($row = mysql_fetch_array($result1) )
	{
		//echo "i'm in while";
		$similar = $row[$column];
		//echo "<a class= $styleclass href=\"search.php?slang=$similar&key_pref=$key_pref_value&vote_flow=0\">$similar</a>";
		//echo "<br>";
		//echo $count;
		if(!in_array($similar,$array))
		{
			//if not in array, add
			$array[$array_pointer]= $similar;
			//echo "added: [$array_pointer]";
			$array_pointer++;
			
		}
		$count++;
		if($count>$control)
		{
			$count=1; //reset count
			break;
		}
	}
	
	//printing out result from select ends with
	//echo "ends with";
	while($row = mysql_fetch_array($result2) )
	{
		//echo "i'm in while";
		$similar = $row[$column];
		//echo "<a class= $styleclass href=\"search.php?slang=$similar&key_pref=$key_pref_value&vote_flow=0\">$similar</a>";
		//echo "<br>";
		//echo $count;
		$count++;
		
		if(!in_array($similar,$array))
		{
			//if not in array, add
			$array[$array_pointer]= $similar;
			$array_pointer++;
			
		}
		
		if($count>$control)
		{
			$count=1; //reset count
			break;
		}
	}
	
	//printing our result from contains
	//echo "contains";
	while($row = mysql_fetch_array($result3) )
	{
		//echo "i'm in while";
		$similar = $row[$column];
		//echo "<a class= $styleclass href=\"search.php?slang=$similar&key_pref=$key_pref_value&vote_flow=0\">$similar</a>";
		//echo "<br>";
		//echo $count;
		
		if(!in_array($similar,$array))
		{
			//if not in array, add
			$array[$array_pointer]= $similar;
			$array_pointer++;
			
		}
		
		$count++;
		if($count>$control)
		{
			$count=1; //reset count
			break;
		}
	}
	
	
	
	
	return $array;
	
}

function print_cheap_guess($array,$key_pref)
{
	if($key_pref=="bur")
	{
		$message = "'gawGawmhawGhcJhw,f <br>";
		$message_singular = "'gawmhawGhcJhw,f <br>";
		$message_class = "textdarkb";
		$seperator = "&nbsp&nbsp&nbsp&nbsp ";
		$styleclass = "randomb";
		$key_pref_value = "bur";
		
		$size = rand(15,60);
		
	}
	else
	{
		$message = "Maybe these are the words you were searching for...<br>";
		$message_singular = "Is this the one you were searching??<br>";
		$message_class = "textdark";
		$seperator = "&nbsp&nbsp&nbsp&nbsp ";
		$styleclass = "random";
		$key_pref_value = "bglish";
		
		$size = rand(9,40);
	}
	
	
	if(count($array)==1)
	{
		echo "<p class=$message_class>$message_singular</p>";
	}
	else if(count($array) > 1)
	{
		echo "<p class=$message_class>$message</p>";
	}
	//printing out the guessed words
	for($i=0; $i < count($array); $i++)
	{
		$size = rand(15,50);
		
		$r = $array[$i];
		$r_decoded = burmese_special_char_decoder($r);
		$r_decoded = htmlspecialchars($r_decoded,ENT_QUOTES);
		
		echo "<a class= $styleclass style=\"font-size: $size;\" href='search.php?slang=$r&key_pref=$key_pref_value&vote_flow=0'>$r_decoded</a>$seperator";
	}
	echo "<br><br>";
}

function chopper($word,$pieces)
{
	//this function chop $word into number of $pieces
	$result = array();
	
	$length = strlen($word);
	$increment = $length/$pieces;
	$pointer = 0;
	for($i=0; $i < $pieces; $i++)
	{
		$result[$i] = substr($word,$pointer,$increment);
		$pointer =$pointer + $increment;
	}
	
	return $result;
}


function print_newest($sqlresult)
{
		while($row = mysql_fetch_array($sqlresult))
		{
		
			if($row['slangBurmese']==NULL)
			{
				//print in english
				//echo "slangburmese is null; i'm gonna print in english";
				$word = $row['slangBurglish'];
				$decoded_word = burmese_special_char_decoder($word);
				$decoded_word = htmlspecialchars($decoded_word,ENT_QUOTES);
				echo "<a class=\"random\" href='search.php?slang=$word&key_pref=bglish&vote_flow=0' >";
				echo $decoded_word;
				echo "</a>";
	
				echo "<P class=\"textdark2\">";
				echo $row['definitionBurglish'] ;
				echo "<br></p>";
				echo "<P class=\"textlight\">";
				echo $row['exampleBurglish'] ;
				echo "<br></p>";
			}
			else
			{
				//print in burmese
				//echo "slangburmese is not null; i'm gonna print in burmese";
				$word = $row['slangBurmese'];
				
				//echo " word is : $word <br>";
				
				$decoded_word = burmese_special_char_decoder($word);
				$decoded_word = htmlspecialchars($decoded_word,ENT_QUOTES);
				
				$def = $row['definitionBurmese'] ;
				$decoded_def = burmese_special_char_decoder($def);
				$decoded_def = htmlspecialchars($decoded_def,ENT_QUOTES);
				
				$example = $row['exampleBurmese'] ;
				$decoded_example = burmese_special_char_decoder($example);
				$decoded_example = htmlspecialchars($decoded_example,ENT_QUOTES);
				
				
				
				
				//echo " decoded word is : $decoded_word <br>";
				echo "<a class=\"randomb\" href='search.php?slang=$word&key_pref=bur&vote_flow=0'>";
				echo $decoded_word;
				echo "</a>";
	
				echo "<P class=\"textdark2b\">";
				echo $decoded_def ;
				echo "<br></p>";
				echo "<P class=\"textlightb\">";
				echo $decoded_example ;
				echo "<br></p>";
			}
		}
}


function print_top($sqlresult)
{
		while($row = mysql_fetch_array($sqlresult))
		{
		
			if($row['slangBurmese']==NULL)
			{
				//print in english
				//echo "slangburmese is null; i'm gonna print in english";
				$word = $row['slangBurglish'];
				$decoded_word = burmese_special_char_decoder($word);
				$decoded_word = htmlspecialchars($decoded_word,ENT_QUOTES);
				echo "<a href=search.php?slang=$word&key_pref=bglish&vote_flow=0 >";
				echo $decoded_word;
				echo "</a><br>";
			}
			else
			{
				//print in burmese
				//echo "slangburmese is not null; i'm gonna print in burmese";
				$word = $row['slangBurmese'];
				$decoded_word = burmese_special_char_decoder($word);
				$decoded_word = htmlspecialchars($decoded_word,ENT_QUOTES);
				echo "<a class=\"bur\" href='search.php?slang=$word&key_pref=bur&vote_flow=0'>";
				echo $decoded_word;
				echo "</a><br>";
	
			}
		}
}

function print_random_font_size($sqlresult)
{
		while($row = mysql_fetch_array($sqlresult))
		{
		
			if($row['slangBurmese']==NULL)
			{
				$size = rand(9,40);
				//print in english
				//echo "slangburmese is null; i'm gonna print in english";
				$word = $row['slangBurglish'];
				
				$decoded_word = burmese_special_char_decoder($word);
				$decoded_word = htmlspecialchars($decoded_word,ENT_QUOTES);
				$decoded_word = wordwrap($decoded_word,10, " ");
				
				//echo $decoded_word;
				
				
				echo "<a class = random style=\"font-size: $size;\" href='search.php?slang=$word&key_pref=bglish&vote_flow=0' >";
				echo $decoded_word;
				echo "</a>&nbsp&nbsp&nbsp&nbsp ";
			}
			else
			{
				$size = rand(15,60);
				//print in burmese
				//echo "slangburmese is not null; i'm gonna print in burmese";
				$word = $row['slangBurmese'];
				$decoded_word = burmese_special_char_decoder($word);
				//$decoded_word = wordwrap($decoded_word,10," ",1);
				$decoded_word = htmlspecialchars($decoded_word,ENT_QUOTES);
				//$decoded_word = "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu";
				$decoded_word = wordwrap($decoded_word,5, "*");
				
				echo "<a class= randomb style=\"font-size: $size;\" href='search.php?slang=$word&key_pref=bur&vote_flow=0'>";
				echo $decoded_word;
				echo "</a>&nbsp&nbsp&nbsp&nbsp ";
	
			}
		}
}

function browse_printer($start_id,$page_size)
{
	for ($i = $start_id; $i < $start_id + $page_size; $i++)
	{
		$result = select_by_id($i);
		print_random_font_size($result);
		
		
		
	}
	
}




function print_message_holder_top($color)
{
	//print the result holder top, the yellowish box top part
	echo "
		<TABLE BORDER=\"0\" CELLPADDING=0 CELLSPACING=0 width=\"464\">

		<TR><TD colspan=\"3\"><img src=\"images/page_top.gif\" border=0 width=\"464\" height=\"27\"></TD></TR>

		<TR><TD background=\"images/page_left.gif\" width=\"23\"><img src=\"images/space.gif\" border=0 width=\"17\" height=\"1\"></TD>

		<TD bgcolor=\"$color\" align=center><img src=\"images/space.gif\" border=\"0\" width=\"428\" height=\"1\"><BR>
		";
}

function print_message_holder_bottom()
{
	//print the result holder top, the yellowish box bottom part
	echo "
			</TD>

			<TD background=\"images/page_right.gif\" width=\"19\"><img src=\"images/space.gif\" border=0 width=\"16\" height=\"1\"></TD>

				</TR>
 


			<TR>
			<TD colspan=\"3\"><img src=\"images/page_bott.gif\" border=0 width=\"464\" height=\"22\"></TD></TR>


			</TABLE>
         ";
	
}

function print_message($m,$color)
{
	print_message_holder_top($color);
	echo $m;
	print_message_holder_bottom();

}

function burmese_special_char_encoder($word)
{
	$word = str_replace("&","0000",$word); // ya kaut will become 0000
	$word = str_replace("'","0001",$word); // da dway will become 0001
	$word = str_replace("\"","0002",$word); //da oat chite
	$word = str_replace("\\","0003",$word); //ei
	$word = str_replace("#","0004",$word); // #
	$word = str_replace("+","0005",$word); // +
	$word = str_replace("<","0006",$word); // +
	$word = str_replace(">","0007",$word); // +
	
	return $word;
}

function burmese_special_char_decoder($word)
{
	$word = str_replace("0000","&",$word); // ya kaut will become 0000
	$word = str_replace("0001","'",$word);
	$word = str_replace("0002","\"",$word);
	$word = str_replace("0003","\\",$word);
	$word = str_replace("0004","#",$word);
	$word = str_replace("0005","+",$word);
	$word = str_replace("0006","<",$word);
	$word = str_replace("0007",">",$word);
	return $word;
}

function print_hidden_keyboard_layout2()
{
	
	echo "<DIV id=\"hidden_burmese_layout\" style=\"position:absolute; display:none; border: 9px solid black; background-color: #CC3300; width: 200px; height: 400px; padding: 8px\">";

	print_burmese_layout();

	echo "<div align=\"right\"><a href=\"#\" onClick=\"overlayclose('hidden_burmese_layout'); return false\">Close Box</a></div></DIV>";
}

function print_hidden_keyboard_layout()
{
	//red bg: CC3300  background-color:red ;
	echo "<DIV id=\"hidden_burmese_layout\" style=\"position:relative;  border: 0px solid red; background-color: CC3300; width: 186px; height: 400px; padding: 0px;display:none;\">";
	//echo "<div align=\"center\" style=\"opacity:0.5;filter: alpha(opacity=50) ;\">Drag Me!</div>";
	echo "<p class=textlight align=center>Drag Me!</p>";
	echo "<p class=textlight>click on a character to type.</p>";
	//echo "<br><p align=center><img src=\"images/arrow_out.png\" border=0></p>";
	print_burmese_layout();

	echo "<div align=\"right\"><a href=\"#\" onClick=\"overlayclose('hidden_burmese_layout'); return false\">Close</a></div></DIV>";
}

//stuffs for user self translation mechanism
function print_hidden_form($formid)
{
	echo "<DIV id=\"hidden_form$formid\" style=\"position:absolute; display:none; border: 0px solid red; background-color: B7B771;
padding: 3px; \">";
	//echo "<div align=\"center\" style=\"opacity:0.5;filter: alpha(opacity=50) ;\">Drag Me!</div>";
	//echo "<p id=message align=center class=textdark>please type this entry in burmese (if you know how).</p>";
	//print_burmese_layout();
	
	echo "<form onsubmit=\"insert_translated('$formid');change_image1('$formid');return false\">
<table border=0 width=320>
<tr><td colspan=\"2\" ><p class=textdark align=center>Please type this entry in burmese (if you know how)</p></td></tr>
<tr><td class=textdark width=20%>Word:</td><td><input id=w$formid class=textboxb></input></td></tr>
<tr><td class=textdark>Definition:</td><td><textarea id=d$formid cols=\"18\" rows=\"8\" class=textareab ></textarea></td></tr>
<tr><td class=textdark>Example:</td><td><textarea id=e$formid cols=\"18\" rows=\"8\" class=textareab ></textarea></td></tr>
<tr><td class=textdark>Author:</td><td><input id=a$formid class=textboxb></input></td></tr>
<tr><td colspan=\"2\" align=center><input type=\"submit\" value=\"Go Ahead\" class=button></input></td></tr>
</table>
			</form>";

	echo "<div align=\"right\"><a href=\"#\" onClick=\"overlayclose('hidden_form$formid'); return false\"><img src=\"images/cancel.png\" border=0></a></div></DIV>";
	//echo "<div id=\"hidden_return_form$formid\" style=\"position:absolute; display:none; border: 0px solid black; background-color: #CC3300;width: 200px; height: 200px;  padding: 0px;\" ></div>";
	
	
	//uncomment this to make it draggable
	//echo "<script type=\"text/javascript\">Drag.init(document.getElementById(\"hidden_form$formid\"));</script>";
	
}



function print_hidden_form_innerHTML($formid)
{
	
	echo "<form onsubmit=\"insert_translated('$formid');change_image1('$formid');return false\">
<table border=0 width=320>
<tr><td colspan=\"2\" ><p class=textdark align=center>Please type this entry in burmese (if you know how)</p></td></tr>
<tr><td class=textdark width=20%>Word:</td><td><input id=w$formid class=textboxb></input></td></tr>
<tr><td class=textdark>Definition:</td><td><textarea id=d$formid cols=\"18\" rows=\"8\" class=textareab ></textarea></td></tr>
<tr><td class=textdark>Example:</td><td><textarea id=e$formid cols=\"18\" rows=\"8\" class=textareab ></textarea></td></tr>
<tr><td class=textdark>Author:</td><td><input id=a$formid class=textboxb></input></td></tr>
<tr><td colspan=\"2\" align=center><input type=\"submit\" value=\"Go Ahead\" class=button></input></td></tr>
</table>
			</form>";

	echo "<div align=\"right\"><a href=\"#\" onClick=\"overlayclose('hidden_form$formid'); return false\"><img src=\"images/cancel.png\" border=0></a></div>";
	//echo "<div id=\"hidden_return_form$formid\" style=\"position:absolute; display:none; border: 0px solid black; background-color: #CC3300;width: 200px; height: 200px;  padding: 0px;\" ></div>";
	
	
	//uncomment this to make it draggable
	//echo "<script type=\"text/javascript\">Drag.init(document.getElementById(\"hidden_form$formid\"));</script>";
	
}

function print_hidden_from_with_value($word, $def, $example, $author,$formid)
{
	$result= "<form onsubmit=\"insert_translated('$formid');change_image('$formid');overlayclose('hidden_form$formid');return false\">
<table border=0>
<tr><td>Word:</td><td><input id=w$formid class=textdarkb value='$word'></input></td></tr>
<tr><td>Definition:</td><td><textarea id=d$formid cols=\"20\" class=textdarkb value='$def' ></textarea></td></tr>
<tr><td>Example:</td><td><textarea id=e$formid cols=\"20\" class=textdarkb value='$example'></textarea></td></tr>
<tr><td>Author:</td><td><input id=a$formid class=textdarkb></input></td></tr>
<tr><td colspan=\"2\" align=center><input type=\"submit\" value=\"Submit\"></input></td></tr>
</table>
			</form>";

	$result= $result. "<div align=\"right\"><a href=\"#\" onClick=\"overlayclose('hidden_form$formid'); return false\">Close</a></div>";
	
	return $result;
}

function print_hidden_unapproved_burmese($id)
{
	$row = mysql_fetch_array(get_everything($id));
	
	$word = burmese_special_char_decoder($row['slangBurmese']);
	$def = burmese_special_char_decoder($row['definitionBurmese']);
	$example = burmese_special_char_decoder($row['exampleBurmese']);
	$author = burmese_special_char_decoder($row['authorBurmese']);
	
	echo "<DIV id=\"hidden_form$id\" style=\"position:absolute; display:none; border: 0px solid black; background-color: #B7B771; 
  padding: 0px;\">";
	echo "
	
	<form onsubmit=\"overlayclose('hidden_form$id');return false\">
<table border=0 width=300>
<tr><td colspan=\"2\" ><p class=textdark>One of our viewers was really nice and typed the burglish in burmese. Does it look ok?</p></td></tr>
<tr><td width=20% class=textdark>Word:</td><td class=textdarkb><div id=w$id>$word</div></input></td></tr>
<tr><td class=textdark>Definition:</td><td class=textdarkb><div id=d$id>$def</div></textarea></td></tr>
<tr><td class=textdark>Example:</td><td class=textdarkb><div id=e$id>$example</div></td></tr>
<tr><td class=textdark>Author:</td><td class=textdarkb><div id=a$id>$author</div></td></tr>

<tr><td colspan=\"2\" align=center><button onclick=\"increase_good($id);change_image1($id);return false\" class=button>Ok</button>
		<button onclick=\"increase_bad($id);change_image1($id); return false\" class=button>Not OK</button></td></tr>";

		
echo  "
</table>
			</form><div align=\"right\"><a href=\"#\" onClick=\"overlayclose('hidden_form$id'); return false\"><img src=\"images/cancel.png\" border=0></a></div></DIV>";
	
	
}

function print_hidden_unapproved_burmese_no_button($id)
{
	$row = mysql_fetch_array(get_everything($id));
	
	$word = burmese_special_char_decoder($row['slangBurmese']);
	$def = burmese_special_char_decoder($row['definitionBurmese']);
	$example = burmese_special_char_decoder($row['exampleBurmese']);
	$author = burmese_special_char_decoder($row['authorBurmese']);
	
	echo "<DIV id=\"hidden_form$id\" style=\"position:absolute; display:none; border: 0px solid black; background-color: #B7B771;
 padding: 0px;\">";
	echo "
	
	<form onsubmit=\"overlayclose('hidden_form$id');return false\">
<table border=0 width=300>
<tr><td colspan=\"2\" ><p class=textdark>Thanks for your input.</p></td></tr>
<tr><td class=textdark width=20%>Word:</td><td class=textdarkb><div id=w$id>$word</div></input></td></tr>
<tr><td class=textdark>Definition:</td><td class=textdarkb><div id=d$id>$def</div></textarea></td></tr>
<tr><td class=textdark>Example:</td><td class=textdarkb><div id=e$id>$example</div></td></tr>
<tr><td class=textdark>Author:</td><td class=textdarkb><div id=a$id>$author</div></td></tr>";

	
		
echo  "
</table>
			</form><div align=\"right\"><a href=\"#\" onClick=\"overlayclose('hidden_form$id'); return false\"><img src=\"images/cancel.png\" border=0></a></div></DIV>";
	
	
}

function print_hidden_original($id)
{
	$row = mysql_fetch_array(select_by_id($id));
	
	$word = burmese_special_char_decoder($row['slangBurglish']);
	$def = burmese_special_char_decoder($row['definitionBurglish']);
	$example = burmese_special_char_decoder($row['exampleBurglish']);
	$author = burmese_special_char_decoder($row['author']);
	
	echo "<DIV id=\"hidden_form$id\" style=\"position:absolute; display:none; border: 0px solid black; background-color: #B7B771;
 padding: 0px;\">";
	echo "
	
	<form onsubmit=\"overlayclose('hidden_form$id');return false\">
<table border=0 width=300>
<tr><td colspan=\"2\" ><p class=textdark>The original version of this entry was like this:</p></td></tr>
<tr><td class=textdark><div id=w$id>$word</div><br></td></tr>
<tr><td class=textdark><div id=d$id>$def</div><br></td></tr>
<tr><td class=textdark><div id=e$id>$example</div></td></tr>
<tr><td colspan=2 align=right class=textdark><div id=a$id>- $author</div></td></tr>";

	
		
echo  "
</table>
			</form><div align=\"right\"><a href=\"#\" onClick=\"overlayclose('hidden_form$id'); return false\"><img src=\"images/cancel.png\" border=0></a></div></DIV>";

}


function print_hidden_original_innerHTML($id)
{
	$row = mysql_fetch_array(select_by_id($id));
	
	$word = burmese_special_char_decoder($row['slangBurglish']);
	$def = burmese_special_char_decoder($row['definitionBurglish']);
	$example = burmese_special_char_decoder($row['exampleBurglish']);
	$author = burmese_special_char_decoder($row['author']);
	
	
	echo "<form onsubmit=\"overlayclose('hidden_form$id');return false\">
<table border=0 width=300>
<tr><td colspan=\"2\" ><p class=textdark>The original version of this entry was like this:</p></td></tr>
<tr><td class=textdark><div id=w$id>$word</div><br></td></tr>
<tr><td class=textdark><div id=d$id>$def</div><br></td></tr>
<tr><td class=textdark><div id=e$id>$example</div></td></tr>
<tr><td colspan=2 align=right class=textdark><div id=a$id>- $author</div></td></tr>";

	
		
echo  "
</table>
			</form><div align=\"right\"><a href=\"#\" onClick=\"overlayclose('hidden_form$id'); return false\"><img src=\"images/cancel.png\" border=0></a></div>";

}

function add_one_click_to_session($id,$goodorbad)
{
	//$id= $_GET["id"];
if(isset($_SESSION[$id."goodbad"]))  
{
	//echo "it is set";
	$_SESSION[$id."goodbad"]=$_SESSION[$id."goodbad"]+1;
}
else  
	{
		//echo "setting 1";
		$_SESSION[$id."goodbad"]=0;
	}
	
}


function insert_burmese_typings($word,$def,$example,$author,$id)
{
	//teh variables are encoded
	$connection = get_ready();
	$sql = "insert into tempstorage (id,slangBurmese, definitionBurmese,exampleBurmese,authorBurmese)
            values ($id,'$word', '$def', '$example','$author');";
	mysql_query($sql);
	mysql_close($connection);
	
	
	
	
	
}
function increase_good($id)
{
	$connection = get_ready();
	$result = mysql_query("SELECT good FROM tempstorage where id=$id;");
	$row = mysql_fetch_array($result);
	
	$value = $row['good'] + 1;
	$sql = "UPDATE tempstorage SET good=$value WHERE id=$id";
	mysql_query($sql);
	mysql_close($connection);
}

function get_good($id)
{
	$connection = get_ready();
	$result = mysql_query("SELECT good FROM tempstorage where id=$id;");
	$row = mysql_fetch_array($result);
	mysql_close($connection);
	return $row['good'];
}

function get_bad($id)
{
	$connection = get_ready();
	$result = mysql_query("SELECT bad FROM tempstorage where id=$id;");
	$row = mysql_fetch_array($result);
	mysql_close($connection);
	return $row['bad'];
}

function get_everything($id)
{
	$connection = get_ready();
	$result = mysql_query("SELECT * FROM tempstorage where id=$id;");
	//$row = mysql_fetch_array($result);
	mysql_close($connection);
	return $result;
}
function increase_bad($id)
{
	$connection = get_ready();
	$result = mysql_query("SELECT bad FROM tempstorage where id=$id;");
	$row = mysql_fetch_array($result);
	
	$value = $row['bad'] + 1;
	$sql = "UPDATE tempstorage SET bad=$value WHERE id=$id";
	mysql_query($sql);
	mysql_close($connection);
}

function change_completed($id,$flag)
{
	//flag
	//0 no burmese
	//1 somebody typed in burmese, but not approved yet
	//2 burmese entry is approved
	$connection = get_ready();
	$sql = "update gaw set completed=$flag where id=$id";
	mysql_query($sql);
	mysql_close($connection);
}

function get_completed($id)
{
	$connection = get_ready();
	$result = mysql_query("SELECT completed FROM gaw where id=$id;");
	$row = mysql_fetch_array($result);
	mysql_close($connection);
	return $row['completed'];
}

function move_to_gaw($id)
{
	$result = get_everything($id); //this gets stuffs from tempstorage
	
	$row = mysql_fetch_array($result);
	
	$w = $row['slangBurmese'];
	$d = $row['definitionBurmese'];
	$e = $row['exampleBurmese'];
	$a = $row['authorBurmese'];
	
	$connection = get_ready();
	$sql = "UPDATE gaw SET slangBurmese='$w', definitionBurmese='$d', exampleBurmese='$e', authorBurmese='$a' WHERE id = $id;";
	mysql_query($sql);
	
	mysql_close($connection);
	
	
	
}

function approval_process($id)
{
	$result = false;
	$total_required = 5;
	$cutoff = 0.6; //60% = 3/5
	$deny_cutoff = 0.4; 
	$value_of_one_vote = 1/$total_required;
	
	
	$result = get_everything($id); //this gets stuffs from tempstorage
	
	$row = mysql_fetch_array($result);
	
	$good = $row['good'];
	$bad= $row['bad'];
	$total_db = $good + $bad;
	
	if($good * $value_of_one_vote >= $cutoff)
	{
		//approve
		move_to_gaw($id);
		change_completed($id,2); //burmese entry got approved
		return "a";
	}
	else if($bad * $value_of_one_vote > $deny_cutoff)
	{
		//deny
		delete_from_temp($id);
		change_completed($id,0);
		return "d";
	}
	
	/*if($total_db == $total_required) //change it back to equal
	{
		//we have enough vote to decide
		if($good/$total_required >= $cutoff)
		{
			//approved - move to gaw, change completed value
			//move_to_gaw($id);
			//change_completed($id,3); //burmese entry got approved
			return true;
		}
		else
		{
			//denied - delete from tempstorage, change completed
			delete_from_temp($id);
			change_completed($id,0);
			return false;
		}
		
	}
	else
	{
		//not enough vote to decide
	}*/
	
	
	return "nothing";
	
}

function delete_from_temp($id)
{
	$connection = get_ready();
	$sql = "DELETE FROM tempstorage where id=$id";
	mysql_query($sql);
	mysql_close($connection);
	
}

function print_div_tag($id)
{
	echo "<DIV id=resulttable$id>";
}

function print_close_div_tag()
{
	echo "</DIV>";
}

function spacer($str,$limit)
{
	//$str will have a space every $limit number
	$start = 0;
	$end = 0;
	if(strlen($str)>$limit)
	{
		$str = substr($str,$start,$end);
		$start = $end;
		$end = $end+ $limit;
	}
	
	return $str;
}

function print_random_amount($n)
{
	print_result_holder_top();
	
	echo "<p class=textdark>Here are some random slangs:</p>";
	$count = get_number_of_rows("gaw");
	
	for($i=1;$i <= $n; $i++)
	{
		$r = rand(1,$count);
		$result = select_by_id($r);
		print_random_font_size($result);
		echo "   ";
		
	}
	
	echo "<br><table width=400>
			<tr><td></td><td align=right width=30%><a href=\"browse.php?start=1\" class=light>browse more...</a></td>
			</tr>
		 </table>";
	print_result_holder_bottom();
}

?>